﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using projectManagementWeb.Validations;

namespace projectManagementWeb.Models.Manager
{
    [CreateProjectClassValidationAttribute]
    public class createProjectModel 
    {
        projectmanagementDBDataContext _dbContext = null;
        public createProjectModel()
        {
            _dbContext = new projectmanagementDBDataContext();
        }


        [Required(ErrorMessage = "El {0} es requerido")]
        [StringLength(100, ErrorMessage = "El {0} debe contener por lo menos un carater y ser menor a 100 caracteres.", MinimumLength = 1)]
        [Display(Name = "Nombre del Proyecto")]
        public string Name { get; set; }


        [Required(ErrorMessage = "La {0} es requerido")]
        [StringLength(100, ErrorMessage = "El {0} debe contener por lo menos un carater y ser menor a 100 caracteres.", MinimumLength = 1)]
        [Display(Name = "Descripción del Proyecto")]
        public string Description { get; set; }

        [Required(ErrorMessage = "La {0} es requerida")]
        //[DataType(DataType.DateTime)]
        [Display(Name = "Fecha de Inicio del Proyecto")]
        public DateTime startDate { get; set; }

        [Required(ErrorMessage = "La {0} es requerida")]
        [Display(Name = "Fecha de Finalización del Proyecto")]
        public DateTime endDate { get; set; }

        [Required(ErrorMessage = "El {0} es requerido")]
        [Display(Name = "Líder de Proyecto")]
        public int projectLeaderID { get; set; }

        [Required(ErrorMessage = "El {0} es requerido")]
        [Display(Name = "Patrocinador")]
        public int sponsorID { get; set; }

        [Required(ErrorMessage = "El {0} es requerido")]
        [Display(Name = "Estatus")]
        public int statusID
        {
            get
            { return 10;}
        }

        public int userID { get; set; }

        public IEnumerable<SelectListItem> ProjectLeaderIDList
        {
            get
            {
               List<SelectListItem> projectLeaderID = _dbContext.spGetAvailableProjectLeaders()
                .Select(i => new SelectListItem
                {
                    Value = i.id.ToString(),
                    Text = i.UserName.ToString()
                }).ToList();

                if (projectLeaderID == null || projectLeaderID.Count() == 0)
                {
                    List<SelectListItem> list = new List<SelectListItem>();
                    list.Add(new SelectListItem
                    {
                        Value = "-1",
                        Text = "No tiene Lideres de Proyecto válidos"
                    });
                    return list;
                }
                return projectLeaderID;
            }
        }
        

        public IEnumerable<SelectListItem> SponsorIDList
        {
            get
            {
               List<SelectListItem> lista = _dbContext.spGetManagers()
                .Select(i => new SelectListItem
                {
                    Value = i.id.ToString(),
                    Text = i.UserName.ToString()
                }).ToList();

                if (lista == null || lista.Count() == 0)
                {
                    List<SelectListItem> lista2 = new List<SelectListItem>();
                    lista2.Add(new SelectListItem
                    {
                        Value = "-1",
                        Text = "No tiene Gerentes válidos"
                    });
                    return lista2;
                }
                return lista;
            }
        }
        

    }
}
